<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="common/include :: header('客户联系人列表')" />
</head>

<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="role-form">
					<div class="select-list">
						<ul>
							<li class="">
								<label>出入库时间：</label>
								<input type="text" class="timeCld" id="startTime" placeholder="开始时间" name="startTime"/>
								<span>-</span>
								<input type="text" class="timeCld" id="endTime" placeholder="结束时间" name="endTime"/>
							</li>
							<li>
								类型：<select name="type" th:with="type=${@dict.getType('stock_bill_type')}">
									<option value="">请选择</option>
									<option th:each="dict : ${type}" th:text="${dict.label}" th:value="${dict.value}"></option>
								</select>
							</li>
							<li>
								状态：<select name="status" th:with="type=${@dict.getType('stock_bill_status')}">
								<option value="">请选择</option>
								<option th:each="dict : ${type}" th:text="${dict.label}" th:value="${dict.value}"></option>
							</select>
							</li>
							<li>
								仓库：<select name="storeId">
								<option value="">请选择</option>
								<option th:each="dict:${storeList}" th:text="${dict.storeName}" th:value="${dict.id}"></option>
							</select>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
							    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
		
			<div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-warning" onclick="stockBill(1)" shiro:hasPermission="business:linkmen:add">
	                <i class="fa fa-plus"></i> 出库
	            </a>
	            <a class="btn btn-success" onclick="stockBill(0)" shiro:hasPermission="business:linkmen:edit">
		            <i class="fa fa-edit"></i> 入库
		        </a>
	        </div>
	        
	        <div class="col-sm-12 select-table table-striped">
			    <table id="bootstrap-table"></table>
			</div>
		</div>
	</div>
	<th:block th:include="common/include :: footer" />
	<th:block th:include="common/include :: datetimepicker" />
	<script th:inline="javascript">


		var billStatesDatas = [[${@dict.getType('stock_bill_status')}]];
		var billTypeDatas = [[${@dict.getType('stock_bill_type')}]];
		var prefix = ctx + "/business/stockBill";
		$(function() {
		    let options = {
		        url: prefix + "/query",
		        createUrl: prefix + "/addPage",
				updateUrl: prefix + "/editPage?id={id}",
				removeUrl: prefix + "/remove",
		        modalName: "出入库库单",

		        columns: [{
		            field: 'id',
		            title: '序号',
					sortable: true
		        },
		        {
		            field: 'type',
		            title: '货物操作',
		            sortable: true,
					formatter: function (value, row, index) {
						return $.table.selectDictLabel(billTypeDatas, value);
					}
		        },
		        {
		            field: 'store.storeName',
		            title: '仓库名',
		            sortable: true
		        },
				{
					field: 'user.userName',
					title: '操作人',
					sortable: true
				},
				{
					field: 'busiDate',
					title: '出入库时间',
					sortable: true,
				},

				{
					field: 'operateDate',
					title: '操作时间',
					sortable: true
				},
				{
					field: 'remark',
					title: '备注',
					sortable: true
				},
				{
					field: 'status',
					title: '状态',
					sortable: true,
					formatter: function (value, row, index) {
						return $.table.selectDictLabel(billStatesDatas, value);
					}
				},
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	let cancelFlag = row.status == 1 ? 'hidden' : '';

		                let actions = [];
		                actions.push('<a class="btn btn-danger btn-rounded ' + cancelFlag + '" href="javascript:void(0)" onclick="cancel(\'' + row.id + '\')"><i class="fa fa-remove"></i>作废</a> ');
						actions.push('<a class="btn btn-info btn-rounded" href="javascript:void(0)" onclick="checkBill(\'' + row.id + '\')"><i class="fa fa-info"></i>查看</a> ');
						return actions.join('');
		            }
		        }]
		    };
		    $.table.init(options);
		});

		function cancel(id) {
			$.modal.confirm("确定要作废当前库单吗？",function () {
				$.operate.get(prefix + "/cancelBill?id="+ id);
			})
		}

		function stockBill(type) {
			$.modal.open("出入库管理", prefix + "/newBill?type=" + type);
		}

		function checkBill(id) {
			$.modal.open("当前库单详情", prefix + "/checkBill?id=" + id);
		}

		$('.timeCld').datetimepicker({
			format: "yyyy-mm-dd",
			autoclose: true
		});
	</script>
</body>
</html>